package com.market.system.server.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.market.common.log.annotation.Log;
import com.market.common.log.enums.BusinessType;
import com.market.common.security.annotation.RequiresPermissions;
import com.market.system.common.domain.Emp;
import com.market.system.server.service.IEmpService;
import com.market.common.core.web.controller.BaseController;
import com.market.common.core.utils.poi.ExcelUtil;
import com.market.common.core.web.page.TableDataInfo;
import com.market.common.core.domain.Result;

/**
 * 员工管理Controller
 *
 * @author market
 * @date 2024-01-14
 */
@RestController
@RequestMapping("/emp")
public class EmpController extends BaseController
{
    @Autowired
    private IEmpService empService;

    /**
     * 查询员工管理列表
     */
    @RequiresPermissions("system:emp:list")
    @GetMapping("/list")
    public Result<TableDataInfo> list(Emp emp)
    {
        startPage();
        List<Emp> list = empService.selectEmpList(emp);
        return getDataTable(list);
    }

    /**
     * 导出员工管理列表
     */
    @RequiresPermissions("system:emp:export")
    @Log(title = "员工管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Emp emp)
    {
        List<Emp> list = empService.selectEmpList(emp);
        ExcelUtil<Emp> util = new ExcelUtil<Emp>(Emp.class);
        util.exportExcel(response, list, "员工管理数据");
    }

    /**
     * 获取员工管理详细信息
     */
    @RequiresPermissions("system:emp:query")
    @GetMapping(value = "/{empId}")
    public Result getInfo(@PathVariable("empId") Long empId)
    {
        return success(empService.selectEmpByEmpId(empId));
    }

    /**
     * 新增员工管理
     */
    @RequiresPermissions("system:emp:add")
    @Log(title = "员工管理", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody Emp emp)
    {
        return toAjax(empService.insertEmp(emp));
    }

    /**
     * 修改员工管理
     */
    @RequiresPermissions("system:emp:edit")
    @Log(title = "员工管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody Emp emp)
    {
        return toAjax(empService.updateEmp(emp));
    }

    /**
     * 删除员工管理
     */
    @RequiresPermissions("system:emp:remove")
    @Log(title = "员工管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{empIds}")
    public Result remove(@PathVariable Long[] empIds)
    {
        return toAjax(empService.deleteEmpByEmpIds(empIds));
    }
}
